import request from '../utils/request'
import type { ApiResponse, PageResult } from '../types/api'

export interface User {
  id?: number
  name: string
  companyName: string
  position: string
  phone: string
  email?: string
  productCategory: string
  createTime?: string
}

export interface UserListParams {
  current: number
  size: number
  name?: string
  phone?: string
  productCategory?: string
}

export const userApi = {
  // 提交用户信息
  submit(user: User) {
    return request.post<ApiResponse<User>>('/api/lottery/user/submit', user)
  },

  // 获取用户列表
  getList(params: UserListParams) {
    return request.get<ApiResponse<PageResult<User>>>('/api/lottery/user/list', { params })
  },

  // 获取用户详情
  getById(id: number) {
    return request.get<ApiResponse<User>>(`/api/lottery/user/${id}`)
  },

  // 更新用户信息
  update(id: number, user: User) {
    return request.put<ApiResponse<User>>('/api/lottery/user', user)
  },

  // 删除用户
  delete(id: number) {
    return request.delete<ApiResponse<void>>(`/api/lottery/user/${id}`)
  },

  // 导出用户列表
  export() {
    return request.get('/api/lottery/user/export', {
      responseType: 'blob'
    })
  }
} 